package cn.lan.scau_hotel_service.service.impl;

import cn.lan.scau_hotel_service.entity.Order;
import cn.lan.scau_hotel_service.entity.User;
import cn.lan.scau_hotel_service.repository.UserRepository;
import cn.lan.scau_hotel_service.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;


@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserRepository userRepository;


    @Override
    public User getUserById(int id) {
        return userRepository.getUserById(id);
    }

    @Override
    public User getUserByOpenId(String openid) {
        return userRepository.getUserByOpenid(openid);
    }

    @Override
    public boolean saveUser(User user) {
        return userRepository.saveAndFlush(user)!=null;
    }

    @Override
    @Transactional
    public boolean deleteUserById(int id) {
        return userRepository.deleteUserById(id)!=0;
    }

    @Override
    @Transactional
    public boolean deleteUserByOpenid(String openid) {
        return userRepository.deleteUserByOpenid(openid)!=0;
    }


    @Override
    public List<User> getOrders() {
        return userRepository.findAll();
    }

}
